<template>
  <div class="changeBillMoney">
    <el-form ref="form" :model="formInline" label-width="100px" class="custom-form" :rules="rules">
      <el-form-item label="含税金额" prop="money_bill">
        <el-input
          class="custom-input"
          type="number"
          v-model="formInline.money_bill"
          placeholder="请输入含税金额"
        >
          <template slot="append">元</template>
        </el-input>
      </el-form-item>
      <el-form-item label>
        <el-button @click="close">取消</el-button>
        <el-button type="primary" @click="submit('form')">确定</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { updateMoneyBill } from "@/api/moneyManagment";
export default {
  name: "changeBillMoney",
  props: {
    row: {
      type: Object,
      default: {}
    }
  },
  mounted() {},
  data() {
    return {
      formInline: {
        money_bill: ""
      },
      rules: {
        money_bill: [
          { required: true, message: "请输入含税金额", trigger: "blur" }
        ]
      }
    };
  },
  mounted() {
    this.initial();
  },
  methods: {
    async initial() {
      let money_bill = this.row.money_bill;
      if (money_bill == "暂无") money_bill = 0;
      this.formInline.money_bill = money_bill;
    },
    submit(formName) {
      this.$refs[formName].validate(async valid => {
        if (valid) {
          let result = await updateMoneyBill({
            id: this.row.id,
            ...this.formInline
          });
          if (result.code == 200) {
            this.$message.success("修改成功");
            setTimeout(() => {
              this.$emit("sureDialog");
            }, 1000);
          }
        }
      });
    },
    close() {
      this.$emit("closeDialog");
    }
  }
};
</script>

<style lang="scss" scoped>
.changeBillMoney {
}
</style>
